<?php
declare(strict_types=1);
/**
 * Created by PhpStorm
 * User: Administrator
 * Date: 2022/10/21
 * Time: 17:16:30
 */

namespace app\shop\controller;

use app\common\service\DecorateService\DecorateTabService;
use app\Normal;
use app\Request;
use think\annotation\Route;
use think\annotation\route\Group;
use think\annotation\route\Middleware;

/**
 * @Group("DecorateTab")
 * @Middleware({shopMiddileware::class})
 */
class DecorateTab extends \app\BaseShopController
{
    /**
     * 微页面列表
     * @Route("lists",method="GET")
     * @param Request $request
     * @return void
     */
    public function lists( Request $request){
        $result = callApi(DecorateTabService::class, 'lists',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 新增微页面
     * @Route("add",method="POST")
     * @return void
     */
    public function add(){
        $result = callApi(DecorateTabService::class, 'add',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'新增名称为【'.$this->_all_data['name'] . '】微页面','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 微页面详情
     * @Route("decorateTabDetails/:id",method="GET")
     * @return void
     */
    public function decorateTabDetails(){
        $result = callApi(DecorateTabService::class, 'details',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 微页面删除
     * @Route("del",method="POST")
     * @return void
     */
    public function del(){
        $result = callApi(DecorateTabService::class, 'del',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'删除ID为【'.$this->_all_data['id'] . '】微页面','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 编辑微页面
     * @Route("edit",method="PUT")
     * @return void
     */
    public function edit(){
        $result = callApi(DecorateTabService::class, 'edit',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'编辑ID为【'.$this->_all_data['id'] . '】微页面','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 发布微页面
     * @Route("release",method="POST")
     * @return void
     */
    public function release(){
        $result = callApi(DecorateTabService::class, 'release',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'发布微页面ID为【'.$this->_all_data['id'] . '】','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
}